package org.linuxsogood.boot.controller;

import org.linuxsogood.boot.grpc.client.HelloWorldClient;
import org.linuxsogood.boot.grpc.client.MetricsClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liu.hongwei
 * @since 2020/11/10 17:56
 *
 * 先用maven protobuf插件调用compile生成相关message文件
 * 再调用compile-custom生成gRPC的相关stub
 */
@RestController
public class GrpcDemoController {

    @Autowired
    private HelloWorldClient helloWorldClient;

    @Autowired
    private MetricsClient metricsClient;

    @GetMapping("/sayHello")
    public String test(String firstName, String lastName) {
        return helloWorldClient.sayHello(firstName, lastName);
    }

    @GetMapping("/metric")
    public String metric() {
        metricsClient.stream();
        return "ok";
    }
}
